
varying vec2 vUv;
uniform float iTime;
uniform vec3 iResolution;
uniform vec4 iMouse;

uniform sampler2D uv_mid;
uniform sampler2D uv_out;
uniform sampler2D uv_head_tail;
uniform sampler2D uv_sides;

// #define uTime (iTime/1000.0)            // iTime时间单位是 s 秒; 需要转换
// #define BASE_COLOR csm_DiffuseColor     // 在kokomi.js中替换无效
#define THRESHOLD 0.0
#define fogTexture uv_out
// #define fogTexture uv_mid



void main() {
    vec2 movingUV = vUv;
    float uTime = iTime;

    movingUV.y += uTime * 0.2;          // 0.2为速度
    // 可选：为了增强深度感，添加UV扭曲
    float distortionStrength = 0.05;
    float distortion = sin(movingUV.y * 10.0 + uTime) * distortionStrength;
    movingUV.x += distortion;

    vec4 op_ctrl_fog = texture( uv_mid, movingUV );
    // 注意头尾的透明度贴图一定要是固定UV坐标
    vec4 op_ctrl_headTail = texture( uv_head_tail, vUv );
    vec4 op_ctrl_sides = texture( uv_sides, vUv );

    // 这个判断参数大概要调整 需要问其他人经验
    /*
    if ( op_ctrl_fog.r < THRESHOLD && op_ctrl_fog.g < THRESHOLD && op_ctrl_fog.b < THRESHOLD ) 
        discard;
    if ( op_ctrl_headTail.r < THRESHOLD && op_ctrl_headTail.g < THRESHOLD && op_ctrl_headTail.b < THRESHOLD ) 
        discard;
    if (  op_ctrl_sides.r < THRESHOLD && op_ctrl_sides.g < THRESHOLD && op_ctrl_sides.b < THRESHOLD )
        discard;
    */
    if ( op_ctrl_fog.r < THRESHOLD ) 
        discard;
    if ( op_ctrl_headTail.r < THRESHOLD ) 
        discard;
    if (  op_ctrl_sides.r < THRESHOLD )
        discard;
    
    csm_DiffuseColor = vec4(0.3686, 0.6353, 0.9608, op_ctrl_fog.r*op_ctrl_headTail.r*op_ctrl_sides.r);
    
    
    // vec2 uv=vUv;
    // vec3 col=.5+.5*cos(iTime+uv.xyx+vec3(0,2,4));
    // csm_DiffuseColor=vec4(col,1.);
}